<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>7、umbraconewssite：新闻详情页 | haijd</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  
  <meta name="keywords" content="Umbraco入门" />
  
  
  
  
  <meta name="description" content="Umbraco入门教程">
<meta name="keywords" content="Umbraco入门">
<meta property="og:type" content="article">
<meta property="og:title" content="7、UmbracoNewsSite：新闻详情页">
<meta property="og:url" content="http://www.hais2.com/2016/01/07/Umbraco-Getting-Started-7/index.html">
<meta property="og:site_name" content="haijd">
<meta property="og:description" content="Umbraco入门教程">
<meta property="og:locale" content="default">
<meta property="og:image" content="http://www.hais2.com/image/umbraco/backoffice38.png">
<meta property="og:image" content="http://www.hais2.com/image/umbraco/backoffice39.png">
<meta property="og:image" content="http://www.hais2.com/image/umbraco/backoffice40.png">
<meta property="og:image" content="http://www.hais2.com/image/umbraco/backoffice41.png">
<meta property="og:image" content="http://www.hais2.com/image/umbraco/backoffice42.png">
<meta property="og:image" content="http://www.hais2.com/image/umbraco/backoffice44.png">
<meta property="og:image" content="http://www.hais2.com/image/umbraco/backoffice43.png">
<meta property="og:image" content="http://www.hais2.com/image/umbraco/backoffice45.png">
<meta property="og:image" content="http://www.hais2.com/image/umbraco/backoffice46.png">
<meta property="og:image" content="http://www.hais2.com/image/umbraco/backoffice47.png">
<meta property="og:image" content="http://www.hais2.com/image/umbraco/backoffice48.png">
<meta property="og:updated_time" content="2017-08-02T15:22:33.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="7、UmbracoNewsSite：新闻详情页">
<meta name="twitter:description" content="Umbraco入门教程">
<meta name="twitter:image" content="http://www.hais2.com/image/umbraco/backoffice38.png">
  
    <link rel="alternate" href="/atom.xml" title="haijd" type="application/atom+xml">
  
  <link rel="icon" href="/css/images/favicon.ico">
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link href="https://fonts.googleapis.com/css?family=Open+Sans|Montserrat:700" rel="stylesheet" type="text/css">
  <link href="https://fonts.googleapis.com/css?family=Roboto:400,300,300italic,400italic" rel="stylesheet" type="text/css">
  <link href="//cdn.bootcss.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">
  <style type="text/css">
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/9749f0/00000000000000000001008f/27/l?subset_id=2&fvd=n5) format("woff2");font-weight:500;font-style:normal;}
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/90cf9f/000000000000000000010091/27/l?subset_id=2&fvd=n7) format("woff2");font-weight:500;font-style:normal;}
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/8a5494/000000000000000000013365/27/l?subset_id=2&fvd=n4) format("woff2");font-weight:lighter;font-style:normal;}
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/d337d8/000000000000000000010095/27/l?subset_id=2&fvd=i4) format("woff2");font-weight:400;font-style:italic;}</style>
    
  <link rel="stylesheet" id="athemes-headings-fonts-css" href="//fonts.googleapis.com/css?family=Yanone+Kaffeesatz%3A200%2C300%2C400%2C700&amp;ver=4.6.1" type="text/css" media="all">
  <link rel="stylesheet" href="/css/style.css">

  <script src="/js/jquery-3.1.1.min.js"></script>

  <!-- Bootstrap core CSS -->
  <link rel="stylesheet" href="/css/bootstrap.css" >
  <link rel="stylesheet" href="/css/hiero.css" >
  <link rel="stylesheet" href="/css/glyphs.css" >
  
    <link rel="stylesheet" href="/css/vdonate.css" >
  

</head>

<script>
var themeMenus = {};

  themeMenus["/"] = "Home"; 

  themeMenus["/archives"] = "Archives"; 

  themeMenus["/categories"] = "Categories"; 

  themeMenus["/tags"] = "Tags"; 

  themeMenus["/about"] = "About"; 

</script>


  <body data-spy="scroll" data-target="#toc" data-offset="50">


  <header id="allheader" class="site-header" role="banner">
  <div class="clearfix container">
      <div class="site-branding">

          <h1 class="site-title">
            
              <a href="/" title="haijd" rel="home"> haijd </a>
            
          </h1>

          
            <div class="site-description">Stay Hungry,Stay Foolish</div>
          
            
          <nav id="main-navigation" class="main-navigation" role="navigation">
            <a class="nav-open">Menu</a>
            <a class="nav-close">Close</a>
            <div class="clearfix sf-menu">

              <ul id="main-nav" class="nmenu sf-js-enabled">
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663"> <a class="" href="/">Home</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663"> <a class="" href="/archives">Archives</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663"> <a class="" href="/categories">Categories</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663"> <a class="" href="/tags">Tags</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663"> <a class="" href="/about">About</a> </li>
                    
              </ul>
            </div>
          </nav>


      </div>
  </div>
</header>




  <div id="container">
    <div id="wrap">
            
      <div id="content" class="outer">
        
          <section id="main" style="float:none;"><article id="post-Umbraco-Getting-Started-7" style="width: 66%; float:left;" class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="clearfix post-1016 post type-post status-publish format-standard has-post-thumbnail hentry category-template-2 category-uncategorized tag-codex tag-edge-case tag-featured-image tag-image tag-template">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" class="article-title" itemprop="name">
      7、UmbracoNewsSite：新闻详情页
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	Posted on <a href="/2016/01/07/Umbraco-Getting-Started-7/" class="article-date">
	  <time datetime="2016-01-07T13:53:36.000Z" itemprop="datePublished">January 7, 2016</time>
	</a>

      
	<span id="busuanzi_container_page_pv">
	  本文总阅读量<span id="busuanzi_value_page_pv"></span>次
	</span>

    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <p>　　这一篇我们创建一个新闻详情页文档类型，然后尝试编辑新闻内容。</p>
<p>　　首先确定新闻详情页需要什么？应该有新闻标题、新闻内容、新闻简介、新闻缩略图；其中后两个是为了在新闻列表展示该新闻信息设置的。确定了这些，现在就可以开始编写了。<a id="more"></a><br>　　打开<strong>Document Types</strong>节点新建一个名为<strong>News Post</strong>的新文档类型，<strong>Master Document Type</strong>同样选择<em>none…</em>。<br>　　接着创建两个Tabs，分别是<strong>Info</strong>和<strong>Content</strong>。<br><img src="/image/umbraco/backoffice38.png" alt=""></p>
<p>　　然后分别设置需要的几个属性：注意用来设置新闻内容的属性<strong>Content</strong>的数据类型设置为<em>Richtext Editor</em>(富文本编辑器);其次我们先不设置新闻缩略图这个属性，因为我们需要去对图片的数据类型做一些修改，控制图片的大小和名称。<br><img src="/image/umbraco/backoffice39.png" alt=""></p>
<p>　　现在去修改设置图片数据类型。打开<strong>Developer</strong>节点，点击<strong>Data Types</strong>节点后面的三个小圆点按钮，新建一个名为<strong>Featured Image</strong>的新数据类型，并且选择属性编辑器为<strong>Image Cropper</strong>。<br>　　解释一下Umbraco中的数据类型(Data Types)：Umbraco中的数据类型都是Umbraco自己定义的，使用的时候只能选择，而不能去新创建一个新的数据类型，那么你会问，那我们刚刚创建的这个也是新的啊？这个确实是新的，但是就算是新的，也必须选择使用什么类型的数据类型作为属性编辑器，也就是<strong>Property editor</strong>这个选项的作用，可以理解为继承的关系吧，Umbraco定义的数据类型都是父类，我们需要一个子类去干实际完成的事，只要继承父类的一些特征就可以了，这就是我们在这里为什么编写新的数据类型的原因，为了让功能更加的细分。<br><img src="/image/umbraco/backoffice40.png" alt=""></p>
<p>　　然后点击<strong>Add new crop</strong>按钮，编辑别名(存储到数据库中的字段名)和图片大小，最后先点击<strong>Save crop</strong>按钮保存编辑，然后点击<strong>Save</strong>按钮保存。<br><img src="/image/umbraco/backoffice41.png" alt=""></p>
<p>　　现在我们可以设置新闻缩略图这个属性了，回到<strong>News Post</strong>文档类型，编辑<strong>News Image</strong>属性。<br><img src="/image/umbraco/backoffice42.png" alt=""></p>
<p>　　然后将<strong>News Post</strong>类型设置成<strong>News List</strong>类型的子类型，因为内容详情是存在于新闻列表下面的。<br><img src="/image/umbraco/backoffice44.png" alt=""></p>
<p>　　接下来去<strong>Templates</strong>节点下编写新闻详情页具体展现的代码。<br>　　先打开<strong>News Post</strong>模板，然后将母板页设置为<strong>Master</strong>。<br><img src="/image/umbraco/backoffice43.png" alt=""></p>
<p>　　然后编写具体的代码，在<strong>News Post</strong>模板中添加如下代码：<br>　　解释一下这几个方法的使用：<code>CurrentPage</code>是获得当前页面的所有数据，也就是当前页面所在的文档类型的所有属性，这是一个动态类型，只能在内容发布后才能获取到实际的值；<code>GetPropertyValue</code>方法可以获取对应的名称的属性的值，需要一个字符串(属性名称)作为参数；<code>CreateData</code>是一个只读属性，用来获取当前页面创建的时间；<code>CreatorName</code>是一个只读属性，用来获取当前页面的创建者。<br><figure class="highlight scala"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@inherits</span> <span class="type">Umbraco</span>.<span class="type">Web</span>.<span class="type">Mvc</span>.<span class="type">UmbracoTemplatePage</span></span><br><span class="line">@&#123;</span><br><span class="line">    <span class="type">Layout</span> = <span class="string">"Master.cshtml"</span>;</span><br><span class="line">&#125;</span><br><span class="line">&lt;div <span class="class"><span class="keyword">class</span></span>=<span class="string">"container"</span> style=<span class="string">"padding-top:30px"</span>&gt;</span><br><span class="line">	&lt;h3 style=<span class="string">"text-align:center"</span>&gt;<span class="meta">@CurrentPage</span>.<span class="type">GetPropertyValue</span>(<span class="string">"title"</span>)&lt;/h3&gt;</span><br><span class="line">	&lt;p style=<span class="string">"text-align:center"</span>&gt;时间：<span class="meta">@CurrentPage</span>.<span class="type">CreateDate</span>.<span class="type">ToLongDateString</span>() 作者：<span class="meta">@CurrentPage</span>.<span class="type">CreatorName</span>.<span class="type">ToString</span>()&lt;/p&gt;</span><br><span class="line">	&lt;hr/&gt;</span><br><span class="line">	<span class="meta">@CurrentPage</span>.<span class="type">GetPropertyValue</span>(<span class="string">"content"</span>)</span><br><span class="line">&lt;/div&gt;</span><br></pre></td></tr></table></figure></p>
<p>　　代码编写完成后，我们回到内容编辑节点<strong>Content</strong>，点击<strong>keji</strong>后面的三个小圆点按钮，创建一个<strong>News Post</strong>类型的页面，编辑所需要的内容。如下：<br><img src="/image/umbraco/backoffice45.png" alt=""><br><img src="/image/umbraco/backoffice46.png" alt=""></p>
<p>　　点击<strong>Save and publish</strong>按钮，但是这时，我们还不能直接去浏览这条新闻，因为还没有设置任何可以指向这条新闻的链接。但是为了查看效果，我们可以点击<strong>Properties</strong>选项卡中的<strong>Link to document</strong>后面的地址，这样就可以查看效果了。<br><img src="/image/umbraco/backoffice47.png" alt=""></p>
<p>　　最后的效果如下：<br><img src="/image/umbraco/backoffice48.png" alt=""></p>
<p>　　下一篇我们将新闻添加到新闻列表页中，这样就可以方便的查看新闻了。</p>

      
    </div>
    <footer class="entry-meta entry-footer">
      
	<span class="ico-folder"></span>
    <a class="article-category-link" href="/categories/Umbraco/">Umbraco</a>

      
  <span class="ico-tags"></span>
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Umbraco入门/">Umbraco入门</a></li></ul>

      
        <div id="donation_div"></div>

<script src="/js/vdonate.js"></script>
<script>
var a = new Donate({
  title: '如果觉得我的文章对您有用，请随意打赏。您的支持将鼓励我继续创作!', // 可选参数，打赏标题
  btnText: 'Donate', // 可选参数，打赏按钮文字
  el: document.getElementById('donation_div'),
  wechatImage: '/css/images/wechatPay.png',
  alipayImage: '/css/images/alipay.jpg'
});
</script>
      

      
        
	<section id="comments" class="comment">
	  <div id="disqus_thread">
	  <noscript>Please enable JavaScript to view the <a href="//disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
	  </div>
	</section>

	<script type="text/javascript">
	var disqus_shortname = 'haijdblog';
	(function(){
	  var dsq = document.createElement('script');
	  dsq.type = 'text/javascript';
	  dsq.async = true;
	  dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
	  (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
	}());
	(function(){
	  var dsq = document.createElement('script');
	  dsq.type = 'text/javascript';
	  dsq.async = true;
	  dsq.src = '//' + disqus_shortname + '.disqus.com/count.js';
	  (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
	}());
	</script>


      
    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2016/01/08/Umbraco-Getting-Started-8/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          8、UmbracoNewsSite：添加新闻列表
        
      </div>
    </a>
  
  
    <a href="/2016/01/06/Umbraco-Getting-Started-6/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">6、UmbracoNewsSite：添加新闻分类</div>
    </a>
  
</nav>

  
</article>

<!-- Table of Contents -->

  <aside id="sidebar">
    <div id="toc" class="toc-article">
    <strong class="toc-title">Contents</strong>
    
      <ol class="nav">None</ol>
    
    </div>
  </aside>
</section>
        
      </div>
      <footer id="footer" class="site-footer">
  

  <div class="clearfix container">
      <div class="site-info">
	      &copy; 2018 haijd All Rights Reserved.
          
            <span id="busuanzi_container_site_uv">
              本站访客数<span id="busuanzi_value_site_uv"></span>人次  
              本站总访问量<span id="busuanzi_value_site_pv"></span>次
            </span>
          
      </div>
      <div class="site-credit">
        Theme by <a href="https://github.com/iTimeTraveler/hexo-theme-hiero" target="_blank">hiero</a>
      </div>
  </div>
</footer>


<!-- min height -->

<script>
    var contentdiv = document.getElementById("content");

    contentdiv.style.minHeight = document.body.offsetHeight - document.getElementById("allheader").offsetHeight - document.getElementById("footer").offsetHeight + "px";
</script>
    </div>
    <!-- <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
    <a href="/categories" class="mobile-nav-link">Categories</a>
  
    <a href="/tags" class="mobile-nav-link">Tags</a>
  
    <a href="/about" class="mobile-nav-link">About</a>
  
</nav> -->
    

<!-- mathjax config similar to math.stackexchange -->

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      processEscapes: true
    }
  });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
    });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for(i=0; i < all.length; i += 1) {
            all[i].SourceElement().parentNode.className += ' has-jax';
        }
    });
</script>

<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  <script src="/fancybox/jquery.fancybox.pack.js"></script>


<script src="/js/scripts.js"></script>
<script src="/js/bootstrap.js"></script>
<script src="/js/main.js"></script>








	<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js">
	</script>






  </div>

  <a id="rocket" href="#top" class=""></a>
  <script type="text/javascript" src="/js/totop.js" async=""></script>
</body>
</html>
